package com.yongqi.duocai.utils;

import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;

import java.util.Objects;


/**
 * 1.描述（@desc）：
 * 2.作者（@author）：夏亮辉
 * 3.日期（@date）：2021年07月06  14:28
 * 4.版本（@version）：1.0.0
 * 5.版权：
 */

public class EmailUtils {

    public static JavaMailSenderImpl JavaMailSender() {
        JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
        mailSender.setHost("smtp.qq.com");
        mailSender.setPort(587);
        mailSender.setUsername("3179219832@qq.com");
        mailSender.setPassword("qkvemouivtpkdgfi");
        return mailSender;
    }

    /**
     * @Description:
     * @Param: [subject:标题, text:内容, email:接收人的邮件地址]
     * @return: void
     * @Author: 你自己
     * @Date: 2020/2/27
     */
    public static void SendSimpleEmail(String subject, String text) {

        JavaMailSenderImpl javaMailSender = JavaMailSender();
        SimpleMailMessage mailMessage = new SimpleMailMessage();
        //邮件的主题
        mailMessage.setSubject(subject);
        mailMessage.setText(text);
        //发送给谁
        mailMessage.setTo("907805794@qq.com");
        // 抄送人
        mailMessage.setCc("3179219832@qq.com");
        //谁发送的
        mailMessage.setFrom(Objects.requireNonNull(javaMailSender.getUsername()));
        javaMailSender.send(mailMessage);
    }

}
